/**
*  \file cancom.h
*
*  \brief
*
*  \author yingqin.wu  yingqin.wu@linde-china.com
*
*
*
*
*
*/
#ifndef CANCOM_H_INCLUDED
#define CANCOM_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../can/can.h"
#include "../canmsg/canmsg.h"
#include "can_ext_tx.h"
#include "can_ext_rx.h"
#include "can_int_tx.h"
#include "can_int_rx.h"
#include "can_li_ion_bms.h"
/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/


/** Object definition.
*
* The struct cancomrx_obj defines the attribute of an object.
*/
struct cancom_obj
{
   U8  node_id;          /**< */
   U32 serial_number;    /**< */
};



/*================================================[ public variables ]================================================*/
struct cancom_obj cancom;
extern F32 const can_resol_rpm              ;
extern F32 const can_resol_torque           ;
extern F32 const can_resol_weight           ;
extern F32 const can_resol_force            ;
extern F32 const can_resol_accel            ;
extern F32 const can_resol_speed            ;
extern F32 const can_resol_ratio            ;
extern F32 const can_resol_charge           ;
extern F32 const can_resol_angle            ;
extern F32 const can_resol_pressure         ;
extern F32 const can_resol_frequency        ;
extern F32 const can_resol_voltage_sensor   ;
extern F32 const can_resol_voltage_drive    ;
extern F32 const can_resol_current_drive    ;
extern F32 const can_resol_current_sensor   ;
extern F32 const can_resol_length           ;
extern F32 const can_resol_temper           ;
											
extern F32 const can_temper_min             ;

/*================================================[ inline functions ]================================================*/
/**
*  use to get bool signal
*
**/
STATIC_INLINE BO signal_bo( struct canmsg* msg, U8 byte, U8 nbit)
{
   return !!( canmsg_data_ptr(msg)[byte] & (1<<nbit));
}

/**
 *  use to set a bool signal
 *
 * */
STATIC_INLINE U8 bit_set_mask(  U8 nbit, BO value )
{
   U8 byte=0;

   if( value)
   {
      byte|=1<<nbit;
   }
   else
   {
      byte=0 ;
   }
   return byte;
}

/*================================================[ public functions ]================================================*/
/**
*  Initialization.
*
*  Initialize the cancom module.
*
*  \return RC_SUCCESS if successful.
*/
RC cancom_initialize( void );
void cancom_reset_node_id( BO value );


/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2018 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
